﻿CREATE TABLE [dbo].[Bill] (
    [BillId]    UNIQUEIDENTIFIER NOT NULL DEFAULT newid(),
	[ClusteredAutoNumber] int NOT NULL IDENTITY, /* used at the server for ordering. saves space over guidpk */
    [CustomerId] CHAR(10) NOT NULL, 
    [SubscriptionId] UNIQUEIDENTIFIER NULL,     /* null if one-time-bill */
	[AmountDue] MONEY NOT NULL, 
	[DateDue] DATE NOT NULL,
    [InvoiceId] UNIQUEIDENTIFIER NULL, /* null until Invoice compiled */
    [DateCreated]  DATETIME         DEFAULT (getdate()) NOT NULL,
    [CreatedBy]    VARCHAR (50)     DEFAULT (suser_sname()) NOT NULL,
    [DateModified] DATE             NULL,
    [ModifiedBy]   VARCHAR (50)     NULL,
    CONSTRAINT [PK_Bill] PRIMARY KEY NONCLUSTERED ([BillId] ASC)
);


GO

CREATE CLUSTERED INDEX [IX_Bill_AutoNumber] ON [dbo].[Bill] ([ClusteredAutoNumber])

GO
